<template>
    <mi-form-page @submit="submit"
                  title="退款/售后编辑"
                  v-model:show="edit.show"
                  :loading="edit.loading"
    >
        <el-form :model="edit.info"
                 :rules="rules"
                 ref="formRef">

            <el-form-item prop="username" label="账号">
                <el-space fill>
                    <mi-input v-model="edit.info.username"/>
                    <mi-form-aux>用户名第一个字符必须为英文，只能由4-12位的字母、数字、汉字、下划线组成</mi-form-aux>
                </el-space>
            </el-form-item>

            <el-form-item prop="avatar" label="头像">
                <mi-up-image v-model="edit.info.avatar" />
            </el-form-item>

            <el-form-item prop="password" label="密码">
                <el-space fill>
                    <mi-input v-model="edit.info.password" type="password" show-password />
                    <mi-form-aux>密码必须包含字母、数字和符号中的两种，由8-16位组成</mi-form-aux>
                </el-space>

            </el-form-item>

        </el-form>
    </mi-form-page>
</template>

<script setup lang="ts">
import {ref, onBeforeMount, inject} from "vue";
import {FormInstance} from "element-plus";
import {useAdminStore} from "@/store/admin";
import Edit from "@/model/edit";

// center==true，表示来自个人中心的编辑，只能编辑当前登录用户自己的信息
const props = withDefaults(defineProps<{
    edit: Edit,
}>(), {

})

const rules : any = {
    username:[{required:true, message:'必填'}],
}

const formRef = ref<FormInstance>()
const groupOptions = ref([])
const admin = useAdminStore()



const submit = () => {
    let url:string = `/index.site/ownInfoEdit`
    props.edit.submit({
        formRef:  formRef.value,
        url: url,
    }).then((res) => {
        // 当前登录用户修改个人信息，更新到状态管理
        admin.info = props.edit.info
    })
}

onBeforeMount(() => {
    props.edit.init(async () => {

        props.edit.info = admin.info

    })
})

</script>

<style scoped>

</style>
